home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
301-325
/
disk_319
/
cnewssrc
/
cnews.orig.lzh
/
libc
/
stdfdopen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-27
|
539b
|
28 lines
/*
* stdfdopen - ensure that the standard i/o descriptors are open,
* to avoid mayhem.
*/
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef NSYSFILE
#define NSYSFILE 3 /* hmm, not on V8 */
#endif
extern int errno;
void
stdfdopen() /* ensure standard descriptors are open */
{
register int fd;
struct stat stbuf;
for (fd = 0; fd < NSYSFILE; fd++)
if (fstat(fd, &stbuf) < 0 && errno == EBADF)
if (open("/dev/null", 2) != fd) /* open read/write */
exit(1); /* bad news */
}